import { Space, Button, TableProps, Tag } from 'antd';
import { useEffect, useMemo, useRef, useState } from 'react';
import useModal from '@/hooks/use-modal/useModal';
// import { SelectionItem, UserSelectModal } from '@/pages/components/selection-modal';
import Tables from '@/components/tables/tables';
import {
  ApprovedList,
  GetDatasetList,
  GetPoliciesRes,
  GetPoliciesResources,
  PoliciesRevokeReq,
  ReloRevokeReq,
  SetPoliciesReq,
  TargetUsers,
} from '@/common/types';
import orgService from '@/api/services/orgService';
import PersonnelModal, { SubmitType } from '@/components/personnel-modal/personnel-modal';
import KnowPermissionsModal from '@/components/know-permissions-modal/know-permissions-modal';
import { formatData } from '@/utils/time';
import NotData from '@/components/NotData';
import TipsModals from '@/components/modals/TipsModals';
import { useOrchestrationStore } from '@/store/orchestrationStore';
import { SvgIcon } from '@/components/icon';

type SharedFields = keyof TargetUsers & keyof GetPoliciesRes;
type ExclusiveFields = Partial<
  Omit<TargetUsers, SharedFields> & Omit<GetPoliciesRes, SharedFields>
>;

type TableDatas = Pick<TargetUsers, SharedFields> & ExclusiveFields;

export interface DataDemoType {
  id: string;
  name: string;
  code: 'admin' | 'knowledge_manager' | 'knowledge_reviewer' | 'unkown';
  description: string;
  tableData: TableDatas[];
  tableColumns: TableProps<TableDatas>['columns'];
}

type UpdateType = 'personnel' | 'other';
interface Props {
  appId: string;
  isPreview?: boolean;
  createUserId?: ApprovedList;
  isPermissions?: boolean;
}

export interface DefaultValueProps {
  checked?: 'all' | 'part';
  id: string;
  name: string;
  type: string;
  resources: GetPoliciesRes['resources'];
}

export interface Option {
  key?: string;
  value: string;
  label: React.ReactNode;
  name?: string;
  resource_type?: string;
  children?: Option[];
  isLeaf?: boolean;
  parentId?: null | string;
  type?: string;
}

const AppPermissionContent = ({
  appId,
  isPreview = false,
  createUserId,
  isPermissions = false,
}: Props) => {
  const isWorkflow = location.pathname.includes('workflow');

  const tablesCopyWriting = (value: GetPoliciesResources[] | undefined): string => {
    if (!value) {
      return '';
    }

    if (value.some((item) => item.resource_id === '*' && item.resource_type === '*')) {
      return '所有知识库/数据接口可问答';
    }

    const filterDatasetAll = value.some(
      (item) => item.resource_type === 'dataset' && item.resource_id === '*',
    );
    const filterFunctionAll = value.some(
      (item) => item.resource_type === 'function' && item.resource_id === '*',
    );

    const filterDataset = value.some((item) => item.resource_type === 'dataset');
    const filterFunction = value.some((item) => item.resource_type === 'function');
    const filterFolder = value.some((item) => item.resource_type === 'folder');

    if (filterDatasetAll && filterFunctionAll) {
      return '所有知识库/数据接口可问答';
    }

    if (filterDatasetAll && !filterFunction) {
      return '所有知识库可问答';
    }

    if (filterFunction && filterFolder) {
      const filterFolderCount = value.filter((item) => item.resource_type === 'folder').length;
      return `${filterFolderCount}个知识库文件夹以及所有数据接口可问答`;
    }

    if (!filterDataset && filterFunctionAll && !filterFolder) {
      return '所有数据接口可问答';
    }

    if (filterDatasetAll && filterFunction) {
      return `所有知识库以及${value.length - 1}个数据接口可问答`;
    }

    if (filterFunctionAll && filterDataset) {
      return `${value.length - 1}个知识库以及所有数据接口可问答`;
    }

    if (filterDataset && filterFunction && filterFolder) {
      const filterFolderCount = value.filter((item) => item.resource_type === 'folder').length;
      return `${filterFolderCount}个知识库文件夹、${
        value.length - filterFolderCount - 1
      }个知识库/数据接口可问答`;
    }

    if (filterDataset && filterFunction) {
      return `${value.length}个知识库/数据接口可问答`;
    }

    if (filterFolder) {
      return `${value.length}个知识库文件夹可问答`;
    }

    if (filterDataset) {
      return `${value.length}个知识库可问答`;
    }

    if (filterFunction) {
      return `${value.length}个数据接口可问答`;
    }

    return '';
  };

  useEffect(() => {
    if (isPermissions) {
      setDatademo((prevDatademo) =>
        prevDatademo.map((item) => {
          if (item.code === 'admin') {
            // 为 admin 替换操作列
            return {
              ...item,
              tableColumns: [
                // 筛选出除 "操作" 列以外的列（避免重复追加）
                ...item.tableColumns.filter((column) => column.title !== '操作'),
                // 替换或新增"操作"列
                {
                  title: '操作',
                  // width:200,
                  dataIndex: 'act',
                  width: '200px',
                  hidden: isPreview,
                  render: (_, record) => {
                    return null;
                  },
                },
              ],
            };
          }
          return item; // 对其他角色不做更改
        }),
      );

      return;
    }

    if (!createUserId) return; // 如果 createUserId 没有值，跳过

    setDatademo((prevDatademo) =>
      prevDatademo.map((item) => {
        if (item.code === 'admin') {
          // 为 admin 替换操作列
          return {
            ...item,
            tableColumns: [
              // 筛选出除 "操作" 列以外的列（避免重复追加）
              ...item.tableColumns.filter((column) => column.title !== '操作'),
              // 替换或新增"操作"列
              {
                title: '操作',
                width: 200,
                dataIndex: 'act',
                // width: '200px',
                hidden: isPreview,
                render: (_, record) => {
                  return record.id === createUserId.create_user_id ? null : (
                    // <a className="!text-@error-color" onClick={() => handleDelete(record, 'admin')}>
                    //   删除
                    // </a>
                    <a
                      className="flex items-center gap-1 !text-@error-color"
                      onClick={() => handleDelete(record, 'admin')}
                    >
                      <SvgIcon icon="message-ic3" size="16px" />
                      <span>删除</span>
                    </a>
                  );
                },
              },
            ],
          };
        }
        return item; // 对其他角色不做更改
      }),
    );
  }, [createUserId, isPermissions]); // 监听 createUserId 变化

  const { configurations, isInOrchestrationPage } = useOrchestrationStore();

  const isEnableFunctionCalling = configurations?.find(
    (config) => config.name === 'enable_function_calling',
  );

  const isDisableDataset = useMemo(
    () =>
      configurations?.find((config) => config.name === 'disable_dataset')?.default_value === '1' ||
      false,
    [],
  );

  const [datademo, setDatademo] = useState<DataDemoType[]>([
    {
      id: '',
      name: '应用管理员',
      code: 'admin',
      description: '可编排应用、管理知识库、审核知识库更新',
      tableData: [],
      tableColumns: [
        {
          title: '名称',
          dataIndex: 'name',
          width: '200px',
        },
        {
          title: '学/工号',
          dataIndex: 'user_id',
          render: (value) => <span>{value ? value : '-'}</span>,
        },
        {
          title: '所属组织',
          dataIndex: 'group',
          render: (_, { group }) => <span>{group?.name}</span>,
        },

        // {
        //   title: '添加日期',
        //   dataIndex: 'create_time',
        //   render: (_, { create_time }) => <span>{formatData(create_time as string)}</span>,
        // },
        {
          title: '操作',
          dataIndex: 'act',
          width: '200px',
          hidden: isPreview,
          render: (_, record) => {
            return record.id === createUserId?.create_user_id ? null : (
              // <a className="!text-@error-color" onClick={() => handleDelete(record, 'admin')}>
              //   删除
              // </a>
              <a
                className="flex items-center gap-1 !text-@error-color"
                onClick={() => handleDelete(record, 'admin')}
              >
                <SvgIcon icon="message-ic3" size="16px" />
                <span>删除</span>
              </a>
            );
          },
        },
      ],
    },
    {
      id: '',
      name: '知识库管理员',
      code: 'knowledge_manager',
      description: '可管理该应用知识库文档',
      tableData: [],
      tableColumns: [
        {
          title: '名称',
          dataIndex: 'name',
          width: '200px',
        },
        {
          title: '学/工号',
          dataIndex: 'user_id',
          render: (value) => <span>{value ? value : '-'}</span>,
        },
        {
          title: '所属组织',
          dataIndex: 'group',
          render: (_, { group }) => <span>{group?.name}</span>,
        },

        // {
        //   title: '添加日期',
        //   dataIndex: 'create_time',
        //   render: (_, { create_time }) => <span>{formatData(create_time as string)}</span>,
        // },
        {
          title: '操作',
          dataIndex: 'act',
          width: '200px',
          hidden: isPreview,
          render: (_, record) => (
            // <a
            //   className="!text-@error-color"
            //   onClick={() => handleDelete(record, 'knowledge_manager')}
            // >
            //   删除
            // </a>
            <a
              className="flex items-center gap-1 !text-@error-color"
              onClick={() => handleDelete(record, 'knowledge_manager')}
            >
              <SvgIcon icon="message-ic3" size="16px" />
              <span>删除</span>
            </a>
          ),
        },
      ],
    },
    {
      id: '',
      name: '知识库审批员',
      description: '可审核新增知识库内容是否合规',
      code: 'knowledge_reviewer',
      tableData: [],
      tableColumns: [
        {
          title: '名称',
          dataIndex: 'name',
          width: '200px',
        },
        {
          title: '学/工号',
          dataIndex: 'user_id',
          render: (value) => <span>{value ? value : '-'}</span>,
        },
        {
          title: '所属组织',
          dataIndex: 'group',
          render: (_, { group }) => <span>{group?.name}</span>,
        },
        // {
        //   title: '添加日期',
        //   dataIndex: 'create_time',
        //   render: (_, { create_time }) => <span>{formatData(create_time as string)}</span>,
        // },
        {
          title: '操作',
          dataIndex: 'act',
          width: '200px',
          hidden: isPreview,
          render: (_, record) => (
            <a
              className="flex items-center gap-1 !text-@error-color"
              onClick={() => handleDelete(record, 'knowledge_reviewer')}
            >
              <SvgIcon icon="message-ic3" size="16px" />
              <span>删除</span>
            </a>
          ),
        },
      ],
    },
    // {
    //   id: '',
    //   name: '问答人员',
    //   description: '可与该应用进行问答与对话',
    //   code: 'unkown',
    //   tableData: [],
    //   tableColumns: [
    //     {
    //       title: '名称',
    //       key: 'index',
    //       width: '200px',
    //       render: (_, record) => <span>{record.target?.target_name}</span>,
    //     },
    //     {
    //       title: '类型',
    //       // dataIndex: 'type',
    //       key: 'index',
    //       // width: '80px',
    //       render: (_, record) => (
    //         <span>{record.target?.target_type === 'user' ? '用户' : '组织'}</span>
    //       ),
    //     },
    //     {
    //       title: '问答权限',
    //       // dataIndex: 'role',
    //       key: 'index',
    //       hidden: isDisableDataset,
    //       render: (_, record) => {
    //         if (!record.resources) {
    //           return <span>-</span>;
    //         }

    //         const dataset = [];
    //         const functions = [];

    //         for (let i = 0; i < record.resources.length; i++) {
    //           const data = record.resources[i];
    //           if (data.resource_type === '*' && data.resource_id === '*') {
    //             dataset.push({ name: '所有知识库', type: 'dataset' });
    //             functions.push({ name: '所有数据接口', type: 'function' });
    //             continue;
    //           }

    //           if (data.resource_type === 'dataset' && data.resource_id === '*') {
    //             dataset.push({ name: '所有知识库', type: 'dataset' });
    //             continue;
    //           }

    //           if (data.resource_type === 'function' && data.resource_id === '*') {
    //             functions.push({ name: '所有数据接口', type: 'function' });
    //             continue;
    //           }

    //           if (data.resource_type === 'folder') {
    //             dataset.unshift({ name: data.resource_name, type: 'folder' });
    //             continue;
    //           }

    //           if (data.resource_type === 'function') {
    //             functions.push({ name: data.resource_name, type: 'function' });
    //             continue;
    //           }

    //           // if (data.resource_type === 'dataset') {
    //           dataset.push({ name: data.resource_name, type: 'dataset' });

    //           // continue;
    //           // }
    //         }

    //         return (
    //           // <>
    //           //   <span>{tagData(record.resources)}</span>
    //           //   {/* <span>{tablesCopyWriting(record.resources)}</span> */}
    //           //   <a className="ml-2 !text-[#0035FF]" onClick={() => hanldeEditData(record)}>
    //           //     {isPreview ? '查看' : '编辑'}
    //           //   </a>
    //           // </>
    //           <div className="flex flex-col gap-2">
    //             <div className="flex flex-wrap gap-2">
    //               {dataset.map((item, index) => (
    //                 <Tag
    //                   color={item.type === 'folder' ? 'blue' : 'orange'}
    //                   key={index.toString()}
    //                   style={{ margin: 0 }}
    //                 >
    //                   {item.name}
    //                 </Tag>
    //               ))}
    //             </div>

    //             <div className="flex flex-wrap gap-2">
    //               {functions.map((item, index) => (
    //                 <Tag color="green" key={index.toString()} style={{ margin: 0 }}>
    //                   {item.name}
    //                 </Tag>
    //               ))}
    //             </div>
    //           </div>
    //         );
    //       },
    //     },
    //     {
    //       title: '操作',
    //       dataIndex: 'act',
    //       width: 200,
    //       hidden: isPreview,
    //       render: (_, record) => (
    //         <>
    //           {!isDisableDataset && (
    //             <a className="!text-@brand-color" onClick={() => hanldeEditData(record)}>
    //               {isPreview ? '查看' : '编辑'}
    //             </a>
    //           )}
    //           <a
    //             className={`!text-@error-color ${!isDisableDataset ? 'ml-5' : ''}`}
    //             onClick={() => handleDelete(record, 'unkown')}
    //           >
    //             删除
    //           </a>
    //         </>
    //       ),
    //     },
    //   ],
    // },
  ]);

  const [deleteData, setDeleteData] = useState<ReloRevokeReq | PoliciesRevokeReq>();

  const [updateCode, setUpdateCode] = useState<DataDemoType['code']>();

  const [selectUser, setSelectUser] = useState<SubmitType[] | DefaultValueProps[]>([]);

  const [defaultValue, setDefaultValue] = useState<DataDemoType['tableData']>([]);

  const [disabledData, setDisabledData] = useState<TableDatas[]>([]);

  const [modalTitle, setModalTitle] = useState<string>('');

  const [editType, setEditType] = useState<boolean>(false);

  const appIdRef = useRef(appId);

  const [option, setOption] = useState<Option[]>([
    {
      key: 'dataset',
      value: '*',
      type: 'dataset',
      label: '知识库文件',
      name: '知识库文件',
      children: [],
      isLeaf: false,
      parentId: null,
    },
    {
      key: 'function',
      value: '*',
      type: 'function',
      label: '数据接口',
      name: '数据接口',
      children: [],
      isLeaf: false,
      parentId: null,
    },
  ]);

  const modal = useModal('update', 'personnel', 'delete', 'edit');

  useEffect(() => {
    if (appId) {
      appIdRef.current = appId;
      fetchRoleAndPolicies();
    }
  }, [appId]);

  const fetchRoleAndPolicies = async () => {
    try {
      await Promise.all([getRole(), getPolicies(), getDataset()]);
    } catch (error) {
      console.error('Error fetching data:', error);
    }
  };

  const getRole = async () => {
    try {
      const res = await orgService.getRole(appId);
      setDatademo((prevData) => {
        const updatedData = [...prevData];
        res.forEach((role) => {
          const index = updatedData.findIndex((item) => item.code === role.code);
          if (index !== -1) {
            updatedData[index] = {
              ...updatedData[index],
              id: role.id,
              tableData: role.target_users ?? [],
            };
          }
        });
        return updatedData;
      });
    } catch (error) {
      console.error('Failed to get roles:', error);
    }
  };

  const getPolicies = async () => {
    try {
      const res = await orgService.getPolicies({ app_id: appId });
      setDatademo((prevData) => {
        const updatedData = [...prevData];
        const index = updatedData.findIndex((item) => item.code === 'unkown');
        if (index !== -1) {
          updatedData[index] = {
            ...updatedData[index],
            tableData: res ?? [],
          };
        }
        return updatedData;
      });
    } catch (error) {
      console.error('Failed to get policies:', error);
    }
  };

  const formatDataset = (value: GetDatasetList[]): Option[] => {
    return value.map((item) => {
      return {
        key: item._id,
        value: item._id,
        type: item.type,
        label: item.name,
        name: item.name,
        children: item.children ? formatDataset(item.children) : [],
        parentId: item.parentId,
      };
    });
  };

  const getDataset = async () => {
    try {
      const data = orgService.getDataset({ appId: appId });

      const dataset = (await data).list.filter((item) => item.type !== 'function');
      const functionDataset = (await data).list.filter((item) => item.type === 'function');

      const formatDatasetData = formatDataset(dataset);
      const formatFunctiontData = formatDataset(functionDataset);

      let optionsKnow = [
        {
          key: 'dataset',
          value: 'datasetRoot',
          type: 'dataset',
          label: '知识库文件',
          name: '知识库文件',
          children: formatDatasetData,
          isLeaf: false,
          parentId: null,
        },
        {
          key: 'function',
          value: 'functionRoot',
          type: 'function',
          label: '数据接口',
          name: '数据接口',
          children: formatFunctiontData,
          isLeaf: false,
          parentId: null,
        },
      ];

      if (!(!isInOrchestrationPage || isEnableFunctionCalling)) {
        optionsKnow = optionsKnow.filter((item) => item.type === 'dataset');
      }
      setOption(optionsKnow);
    } catch (e) {
      console.log(e);
    }
  };

  /**
   * @description: 新增用户弹窗
   * @return {*}
   */
  const hanldeUpdate = (value: DataDemoType, type: UpdateType = 'other') => {
    setUpdateCode(value.code);
    if (value.code === 'admin') {
      setModalTitle('应用管理员');
    }
    if (value.code === 'knowledge_manager') {
      setModalTitle('知识库管理员');
    }

    if (value.code === 'knowledge_reviewer') {
      setModalTitle('知识库审批员');
    }

    if (value.code === 'unkown') {
      setModalTitle('问答人员');
    }

    let tableData = value.tableData;

    if (type !== 'other') {
      tableData = tableData.map((item) => {
        return {
          id: item.target?.target_id,
          name: item.target?.target_name,
          resources: item.resources,
          type: item.target?.target_type,
        };
      });
    }

    const temp = datademo.find((item) => item.code === 'admin')?.tableData;

    if (value.code !== 'admin') {
      setDisabledData(temp ?? []);
    } else {
      setDisabledData([{ id: createUserId?.create_user_id }]);
    }

    setDefaultValue(tableData);

    // 其他
    modal.update.open();
  };

  const handleDelete = (value: TableDatas, type?: any) => {
    if (value.id) {
      setDeleteData({ app_id: appIdRef.current, role_code: type, user_ids: [value?.id] });
    } else {
      setDeleteData({
        app_id: appIdRef.current,
        target: {
          target_id: value.target?.target_id as string,
          target_type: value.target?.target_type as string,
        },
      });
    }
    modal.delete.open();
  };

  const handleDeleteData = () => {
    if (!deleteData) {
      return;
    }

    modal.delete.startLoading();
    if ('role_code' in deleteData && 'user_ids' in deleteData) {
      orgService
        .roleRevoke(deleteData)
        .then((res) => {
          setDatademo((prev) => {
            return prev.map((item) => {
              if (item.code === deleteData.role_code) {
                return {
                  ...item,
                  tableData: item.tableData.filter((item) => item.id !== deleteData.user_ids[0]),
                };
              }
              return item;
            });
          });
          modal.delete.close();
        })
        .finally(() => {
          modal.delete.stopLoading();
        });
    } else {
      orgService
        .policiesRevoke(deleteData)
        .then((res) => {
          modal.delete.close();
          console.log(res);
          getPolicies();
        })
        .finally(() => {
          modal.delete.stopLoading();
        });
    }
  };

  const hanldeEditData = (value: TableDatas) => {
    // hanldeUpdate([value])
    setEditType(true);
    setSelectUser([
      {
        id: value.target?.target_id || '',
        name: value.target?.target_name || '',
        resources: value.resources || [],
        type: value.target?.target_type || 'user',
      },
    ]);
    modal.personnel.open();
  };

  const handlePersonnelSubmit = (value: SubmitType[]) => {
    if (updateCode === 'unkown') {
      if (isDisableDataset) {
        const result = value.map((item) => ({
          resources: [
            {
              action: 'qa',
              resource_id: '*',
              resource_type: '*',
            },
          ],
          target: {
            target_type: item.type,
            target_id: item.id,
          },
        }));

        orgService.setPolicies({ app_id: appId, statements: result }).then((res) => {
          getPolicies();
          modal.update.close();
          modal.personnel.close();
        });
        return;
      }

      setSelectUser(value);
      modal.personnel.open();
      return;
    }

    modal.update.startLoading();
    orgService
      .assignRole({
        app_id: appId,
        role_code: updateCode as 'admin' | 'knowledge_manager' | 'knowledge_reviewer',
        user_ids: value.map((item) => item.id),
      })
      .then((res) => {
        console.log(res);
        getRole();
        modal.update.close();
      })
      .finally(() => {
        modal.update.stopLoading();
      });
  };

  const handleKnowSubmit = (value: SetPoliciesReq['statements']) => {
    if (editType) {
      orgService.setPoliciesOne({ app_id: appId, statement: value[0] }).then((res) => {
        modal.personnel.close();
        modal.update.close();
        getPolicies();
        setEditType(false);
      });
    } else {
      orgService.setPolicies({ app_id: appId, statements: value }).then((res) => {
        modal.personnel.close();
        modal.update.close();
        getPolicies();
        setEditType(false);
      });
    }
  };

  const filteredData = isDisableDataset
    ? datademo.filter(
        (item) => item.code !== 'knowledge_manager' && item.code !== 'knowledge_reviewer',
      )
    : datademo;

  return (
    <div className="mr-4 flex h-full flex-col gap-4">
      {appId ? (
        filteredData.map((item, index) => {
          const btnStatus = isPreview;
          const permissions = isPermissions && item.code === 'admin';

          return (
            <div className="flex flex-1 flex-col rounded-xl bg-white p-4" key={index.toString()}>
              <div className="flex justify-between">
                <div>
                  <div className="text-cn-16-blod text-text-5">
                    {item.name}({item.tableData.length})
                  </div>

                  <div className=" mt-[2px] text-cn-14 text-text-3">{item.description}</div>
                </div>

                {!(btnStatus || permissions) && (
                  // <Button
                  //   type="primary"
                  //   shape="round"
                  //   onClick={() =>
                  //     hanldeUpdate(item, item.name.includes('问答人员') ? 'personnel' : 'other')
                  //   }
                  // >
                  //   新增
                  // </Button>
                  <div
                    className=" flex  h-[32px] w-[68px] cursor-pointer items-center justify-center rounded-md  border !border-@brand-color !text-@brand-color"
                    onClick={() =>
                      hanldeUpdate(item, item.name.includes('问答人员') ? 'personnel' : 'other')
                    }
                  >
                    <SvgIcon icon="message-ic13" size="15" className="mr-1" />
                    新增
                  </div>
                )}
              </div>

              {item.tableData && item.tableData.length > 0 ? (
                <div style={{ marginTop: '16px' }}>
                  <Tables
                    columns={item.tableColumns}
                    dataSource={item.tableData}
                    rowKey={item.code === 'unkown' ? (r) => r.target?.target_id as string : 'id'}
                    scroll={item.code === 'unkown' ? { y: 55 * 10 } : { y: 55 * 5 }}
                    paginationHide
                  />
                </div>
              ) : (
                <NotData iconSize={80} textClassName={'text-sm'} />
              )}
            </div>
          );
        })
      ) : (
        <NotData />
      )}

      <TipsModals open={modal.delete.isOpen} onCancel={modal.delete.close} onOk={handleDeleteData}>
        确认要删除用户信息，删除后无法恢复
      </TipsModals>

      <PersonnelModal
        title={`选择${modalTitle}`}
        appId={appId}
        onSubmit={handlePersonnelSubmit}
        isCheckBox={updateCode === 'unkown'}
        open={modal.update.isOpen}
        onCancel={modal.update.close}
        confirmLoading={modal.update.isLoading}
        defaultValue={defaultValue}
        disabled={disabledData}
      />

      <KnowPermissionsModal
        open={modal.personnel.isOpen}
        onCancel={modal.personnel.close}
        userData={selectUser}
        options={option}
        onSubmit={handleKnowSubmit}
        isPreview={isPreview}
        isWorkflow={isWorkflow}
        isKnow={!isInOrchestrationPage || isEnableFunctionCalling ? true : false}
      />
      {/* <SelectKnowModal /> */}
    </div>
  );
};

export default AppPermissionContent;
